/**
 * @author Luc Yriarte
 * 
 * Licence : BSD http://www.opensource.org/licenses/bsd-license.php
 *  
 */
package basicSim;

public class VectorArrow extends Object3D {

	/**
	 * V shaped arrow. 
	 * Middle point is at vector origin, 
	 * top point at vector extremity.
	 */
	
	static int D_TAIL = 2;

	double length;

	// Arrow on the Y axis.
	public void init(double l) {
		length = l;
		Vector3D v[] = new Vector3D[4];
		// V shaped arrow
		v[0] = new Vector3D(0,0,0);
		v[1] = new Vector3D(-length/(2*D_TAIL),-length/D_TAIL,0);
		v[2] = new Vector3D(0,length,0);
		v[3] = new Vector3D( length/(2*D_TAIL),-length/D_TAIL,0);
		init(v);
	}
	
	// Init from vector
	public void init(Vector3D vect) {
		double x,y,z;
		x = vect.getCell()[0][0];
		y = vect.getCell()[0][1];
		z = vect.getCell()[0][2];
		length = vect.norm();
		Vector3D v[] = new Vector3D[4];
		// Nawac...
		v[0] = new Vector3D(0,0,0);
		v[1] = new Vector3D(-x/(2*D_TAIL),-y/D_TAIL,-z/D_TAIL);
		v[2] = new Vector3D(x,y,z);
		v[3] = new Vector3D( x/(2*D_TAIL),-y/D_TAIL,-z/D_TAIL);
		init(v);
	}
	
	// Init from vertices
	public void init(Vector3D v[]) {
		nFacet = 1;
		facet = new PolygonEdgeIndexes[nFacet];
		// one facet with 4 edges
		facet[0] = new PolygonEdgeIndexes(this, 4);
		// 4 edges
		int[][] e = new int[4][2];
		for (int i = 0; i < 4; i++) {
			e[i][0] = i;
			e[i][1] = (i + 1) % 4;
			facet[0].edge[i] = i;
		}
		mesh = new Mesh(4, 4, v, e);
	}
	
	public VectorArrow(double l) {
		super();
		init(l);
	}
	
	public VectorArrow(Vector3D vect) {
		super();
		init(vect);
	}
	
	public String strObject(int nTab) {
		String str = "", strTab = "";
		for (int i = 0; i < nTab; i++)
			strTab += "\t";
		str += strTab + "{ arrow l=" + new Double(length).toString() + "\n";
		str += strCoord(nTab);
		str += strColor(nTab);
		str += strChild(nTab);
		str += strTab + "}\n";
		return str;
	}


}
